<?php
namespace Client\Table;

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Insert;


class FavoritesTable extends CommonTable
{
    protected $table = 'hy_favorites';
    protected $id = 'favorite_id';
    
    
    /**
     * 获取我的收藏品
     * // select o.* from hy_favorites f inner join hy_organization o on o.org_id=f.org_id and f.user_id=123 \G
     * 
     *         $select->join(
            array('pc' => 'hy_product_category'),
            'pc.product_id = hy_product.product_id',
            array() ,
            $select::JOIN_RIGHT
            );
    
        $select->where(array('pc.category_id' => $cate_id));
        $select->order(array('top desc'));
     * @return array
     */
    public function getMyFavorites($params){
    	
    	$select = new Select(array("f"=>$this->getTable()));
    	$select->join(array("o"=>"hy_organization"),"o.org_id=f.org_id",array('org_id', 'org_name', 'org_thumb_image'));
    	$select->where(array('f.user_id' => $params['user_id']));
    	//$query = $select->getSqlString($this->adapter->getPlatform());
    	//echo $query;die;
    	$rowset = $this->selectWith($select);
    	$result = $rowset->toArray();
    	return $result;
    	
    }
    
    
    /**
     * 取得
     * @param number $limit
     * @param string $paginated
     */
    public function getFavorites($query) {
        $select = new Select($this->getTable());
        $select->columns( array(
            "*",
        ));
        $select->where(array('user_id' => $query['user_id']));
        if($query['org_id']){
            $select->where(array('org_id' => $query['org_id']));
        }
        $rowset = $this->selectWith($select);
        $result = $rowset->toArray();
        return $result;
    }
    /**
     * 收藏店铺
     * @param number $limit
     * @param string $paginated
     */
    public function create($favorites) {
        $result = $this->insert($favorites);
        return $result;
    }
    
    
    public function updateById($data, $id)
    {
        return $this->update($data, array('id' => $id));
    }
    
}